package hongcaosp.app.android.user.settings.info.presenter;

import hongcaosp.app.android.login.UserToken;
import hongcaosp.app.android.modle.BaseResponse;
import hongcaosp.app.android.modle.DataCallBack;
import hongcaosp.app.android.modle.impl.UserModleImpl;
import hongcaosp.app.android.modle.mi.UserModle;
import hongcaosp.app.android.user.settings.info.iview.UpdateUserInfoIView;
import xlj.lib.android.base.component.BasePresenter;
import xlj.lib.android.base.toastcompat.ToastManager;

/**
 * 用户修改资料
 */
public class UpdateUserInfoPresenter extends BasePresenter {

    private UpdateUserInfoIView view;
    private UserModle userModle;

    public UpdateUserInfoPresenter(UpdateUserInfoIView view) {
        this.view = view;
        this.userModle = new UserModleImpl();
    }

    /**
     * 保存
     * @param value
     * @param type 1-昵称 2-签名 6-学校
     */
    public void save(String value,int type) {
        switch (type) {
            case 1:
                saveInfo(value,"","",-1,"","");
                break;
            case 2:
                saveInfo("",value,"",-1,"","");
                break;
            case 3:
                saveInfo("","","",Integer.valueOf(value),"","");
                break;
            case 4:
                saveInfo("","","",-1,value + " 00:00:00","");
                break;
            case 5:
                saveInfo("","","",-1,"",value);
                break;
            case 6:
                saveInfo("","",value,-1,"","");
                break;
        }

    }

    private void saveInfo(String nickName,String userComment,String schoolName,int sex,String birthday,String locality) {
        userModle.editInfo(UserToken.getDefault().getToken(),
                "",
                nickName,
                "", //抖音好
                userComment,    //个性
                "", //学校
                schoolName, //学校
                sex, //性别
                birthday, //生日
                locality, //地址
                new DataCallBack<BaseResponse>() {

                    @Override
                    public void onGetData(BaseResponse data) {
                        super.onGetData(data);
                        view.saveResult(data == null ? "修改失败" : data.getMessage(),data == null ? -1 : data.getCode());
                    }

                    @Override
                    public void onFail(int code, String errorMessage) {
                        super.onFail(code, errorMessage);
                        ToastManager.getInstance().showToast(errorMessage);
                    }
                });
    }
}
